﻿using PARK.Common.Const;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yitter.IdGenerator;

namespace PARK.Attend.Entitys.Entity
{
    /// <summary>
    /// 特殊日期
    /// </summary>
    [SugarTable("attend_specialdate")]
    [Tenant(ClaimConst.TENANT_ID)]
    public class SpecialDateEntity
    {
        /// <summary>
        /// 主键Id
        /// </summary>
        [SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
        public string id { get; set; }
        /// <summary>
        /// 开始日期
        /// </summary>
        [SugarColumn(ColumnName = "begspdate")]
        public string begspdate { get; set; }
        /// <summary>
        /// 结束日期
        /// </summary>
        [SugarColumn(ColumnName = "endspdate")]
        public string endspdate { get; set; }
        /// <summary>
        /// 工作类型  0休息 1上班
        /// </summary>
        [SugarColumn(ColumnName = "worktype")]
        public int worktype { get; set; }
        /// <summary>
        /// 删除标记
        /// </summary>
        [SugarColumn(ColumnName = "DeleteMark")]
        public int DeleteMark { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [SugarColumn(ColumnName = "Description")]
        public string description { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [SugarColumn(ColumnName = "CreateDate")]
        public DateTime? CreateDate { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [SugarColumn(ColumnName = "CreateUserId")]
        public string CreateUserId { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [SugarColumn(ColumnName = "CreateUserName")]
        public string CreateUserName { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [SugarColumn(ColumnName = "LastModifyDate")]
        public DateTime? LastModifyDate { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [SugarColumn(ColumnName = "LastModifyUserId")]
        public string LastModifyUserId { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [SugarColumn(ColumnName = "LastModifyUserName")]
        public string LastModifyUserName { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [SugarColumn(ColumnName = "CompanyId")]
        public string CompanyId { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [SugarColumn(ColumnName = "CompanyName")]
        public string CompanyName { get; set; }


        /// <summary>
        /// 创建
        /// </summary>
        public virtual void Create()
        {
            var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
            var userName = App.User.FindFirst(ClaimConst.CLAINM_REALNAME)?.Value;
            this.id = YitIdHelper.NextId().ToString();
            if (!string.IsNullOrEmpty(userId))
            {
                this.DeleteMark = 0;
                this.CreateDate = DateTime.Now;
                this.CreateUserId = userId;
                this.CreateUserName = userName;
                this.CompanyId = App.User.FindFirst(ClaimConst.CLAINM_CompanyId)?.Value;
                this.CompanyName = App.User.FindFirst(ClaimConst.CLAINM_CompanyName)?.Value;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        public virtual void LastModify(string Id)
        {
            this.id = Id;
            var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
            var userName = App.User.FindFirst(ClaimConst.CLAINM_REALNAME)?.Value;
            if (!string.IsNullOrEmpty(userId))
            {
                this.LastModifyDate = DateTime.Now;
                this.LastModifyUserId = userId;
                this.LastModifyUserName = userName;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        public virtual void Delete(string Id)
        {
            this.id = Id;
            var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
            var userName = App.User.FindFirst(ClaimConst.CLAINM_REALNAME)?.Value;
            this.DeleteMark = 1;
        }
    }
}
